package com.gxa.controller;


import com.gxa.common.JsonResult;
import com.gxa.common.PageRecv;
import com.gxa.common.R;

import com.gxa.pojo.*;
import com.gxa.service.EmployeeService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;




@Controller
@Api(tags = "员工管理接口—陈峰江")
@RequestMapping("/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;





    /*
     *  页码搜索
     */

    @RequestMapping(value = "/queryEmployeePage",method = RequestMethod.GET)
    @ApiOperation(value = "页码数查询员工",notes = "页码数查询员工",httpMethod = "get", response = JsonResult.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name ="page" ,value = "当前页码数,默认为1",paramType = "query",required = false,dataType ="String" ),
            @ApiImplicitParam(name ="limit" ,value = "每页显示条数,默认为10",paramType = "query",required = false,dataType ="String"),
    })
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
            @ApiResponse(code=500,message = "后台错误"),
    })
    @ResponseBody
    public JsonResult queryEmployee(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit){


        return  employeeService.queryEmployeeListPage(page,limit);
    }




    /*
     *  查询所有员工不分页
     */

    @RequestMapping(value = "/queryEmpList",method = RequestMethod.POST)
    @ApiOperation(value = "查询员工",notes = "查询员工",httpMethod = "post", response = JsonResult.class)
    @ResponseBody
    public JsonResult queryEmpList(){

        return  employeeService.queryEmpList();
    }




     /*
      *  模糊查询，根据员工员工账号、电话、姓名查询、id
      */
    @RequestMapping(value = "/queryEmployeeList",method = RequestMethod.GET)
    @ApiOperation(value = "员工搜索",notes = "页面搜索",httpMethod = "GET", response = JsonResult.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码数,默认为1",paramType = "query",required = false,dataType ="String" ),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数,默认为10",paramType = "query",required = false,dataType ="String" ),
            @ApiImplicitParam(name = "search",value = "搜索条件",paramType = "query",required = false,dataType ="String" )
    })
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
            @ApiResponse(code=500,message = "后台错误"),
    })
    @ResponseBody
    public JsonResult queryEmployeeList(@RequestParam(defaultValue = "1")Integer page ,@RequestParam(defaultValue = "10")Integer pageSize ,String search){
        JsonResult jsonResult = employeeService.queryEmployee(page,pageSize,search);


        return jsonResult;
    }






    /*
     *  角色权限查询
     */
    @RequestMapping(value = "/queryAnthority",method = RequestMethod.POST)
    @ApiOperation(value = "角色权限查询",notes = "通过角色名称查询权限",httpMethod = "get",response = R.class)
    @ApiResponses({
            @ApiResponse(code = 200,message = "查询成功"),
            @ApiResponse(code = 400,message = "参数接口问题"),
            @ApiResponse(code = 500,message = "后端问题"),
    })
    @ResponseBody
    public R queryAnthority(@RequestBody @ApiParam(name = "role",value = "角色名称查询权限") Role role){


        return employeeService.queryAnthority(role);
    }




   /*
    *  修改员工
    */
    @RequestMapping(value = "/updateEmployee",method = RequestMethod.POST)
    @ApiOperation(value = "修改员工信息",notes = "以实体对象增加员工",httpMethod = "post",response = JsonResult.class)
    @ApiResponses({
            @ApiResponse(code = 200,message = "查询成功"),
            @ApiResponse(code = 400,message = "参数接口问题"),
            @ApiResponse(code = 500,message = "后端问题"),
    })
    @ResponseBody
    public JsonResult updateEmployee(@RequestBody @ApiParam(name = "employee",value = "员工") Employee employee){

        JsonResult r=employeeService.updateEmployee(employee);
        return r;
    }





    /*
     *  添加员工
     */
    @RequestMapping(value = "/addEmployee",method = RequestMethod.POST)
    @ApiOperation(value = "添加员工接口",notes = "以实体对象增加员工",httpMethod = "post",response = R.class)
    @ApiResponses({
            @ApiResponse(code = 200,message = "查询成功"),
            @ApiResponse(code = 400,message = "参数接口问题"),
            @ApiResponse(code = 500,message = "后端问题"),
    })
    @ResponseBody
    public R addEmployee(@RequestBody @ApiParam(name = "employee",value = "添加员工") Employee employee){

        R r=employeeService.addEmployee(employee);
        return r;
    }






    /*
     *  添加部门
     */
    @RequestMapping(value = "/addDept",method = RequestMethod.POST)
    @ApiOperation(value = "添加部门",notes = "添加部门",response = R.class,httpMethod = "post")
    @ApiResponses({
            @ApiResponse(code = 200,message = "查询成功"),
            @ApiResponse(code = 400,message = "参数接口问题"),
            @ApiResponse(code = 500,message = "后端问题"),
    })
    @ResponseBody
    public R addDept(@RequestBody @ApiParam(name = "dept",value = "添加部门") Dept dept){
        R r= employeeService.addDept(dept);

        return r;
    }





    /*
     *  修改部门
     */
    @RequestMapping(value = "updateDept",method = RequestMethod.POST)
    @ApiOperation(value = "修改部门",notes = "通过查询部门id修改部门名称",response = R.class,httpMethod = "post")
    @ApiResponses({
            @ApiResponse(code = 200,message = "查询成功"),
            @ApiResponse(code = 400,message = "参数接口问题"),
            @ApiResponse(code = 500,message = "后端问题"),
    })

    @ResponseBody
    public R updateDept(@RequestBody @ApiParam(name ="dept" ,value ="通过查询部门id修改部门名称") Dept dept){

        R r=employeeService.updateDept(dept);
        return r;
    }






    /*
     *  修改权限
     */
    @RequestMapping(value = "/delAnthority",method = RequestMethod.POST)
    @ApiOperation(value = "修改权限",notes = "通过查询权限id，删除权限",response = R.class,httpMethod = "post")
    @ApiResponses({
            @ApiResponse(code = 200,message = "删除成功"),
            @ApiResponse(code = 400,message = "参数接口问题"),
            @ApiResponse(code = 500,message = "后端错误"),
    })
    @ResponseBody
    public R updateAnthority(@RequestBody @ApiParam(name ="Role_Anthority" ,value ="查询角色权限查询id再循环添加") Role_Anthority role_anthority){


        return  employeeService.updateAnthority(role_anthority);
    }





    /*
     *  查询角色分页
     */
    @RequestMapping(value = "/queryRole",method = RequestMethod.GET)
    @ApiOperation(value = "角色查询分页",notes = "返回所有角色",response =JsonResult.class,httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="page" ,value = "当前页码数,默认为1",required = false,paramType = "query",dataType ="String" ),
            @ApiImplicitParam(name ="pageSize" ,value = "每页显示条数,默认为10",required = false,paramType = "query",dataType ="String"),
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "删除成功"),
            @ApiResponse(code = 400,message = "参数接口问题"),
            @ApiResponse(code = 500,message = "后端错误"),
    })
    @ResponseBody
    public JsonResult queryRole(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10")Integer pageSize){

        return  employeeService.queryRole(page,pageSize);
    }


    /*
     *  查询角色不分页
     */
    @RequestMapping(value = "/queryRole1",method = RequestMethod.GET)
    @ApiOperation(value = "查询角色不分页",notes = "返回所有角色",response =JsonResult.class,httpMethod = "GET")
    @ApiResponses({
            @ApiResponse(code = 200,message = "删除成功"),
            @ApiResponse(code = 400,message = "参数接口问题"),
            @ApiResponse(code = 500,message = "后端错误"),
    })
    @ResponseBody
    public JsonResult queryRole1(){

        return  employeeService.queryRole1();
    }



     /*
      *  查询部门(分页)
      */
    @RequestMapping(value = "/queryDept",method = RequestMethod.GET)
    @ApiOperation(value = " 查询部门(分页)",notes = "返回所有部门",response =JsonResult.class,httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="page" ,value = "当前页码数,默认为1",required = false,paramType = "query",dataType ="String" ),
            @ApiImplicitParam(name ="pageSize" ,value = "每页显示条数,默认为10",required = false,paramType = "query",dataType ="String"),
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "删除成功"),
            @ApiResponse(code = 400,message = "参数接口问题"),
            @ApiResponse(code = 500,message = "后端错误"),
    })
    @ResponseBody
    public JsonResult queryDept(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10")Integer pageSize){

        return  employeeService.queryDept(page,pageSize);
    }

    /*
    *  查询部门(不分页)
    */
    @RequestMapping(value = "/queryDept1",method = RequestMethod.GET)
    @ApiOperation(value = "部门查询(不分页)",notes = "返回所有部门",response =JsonResult.class,httpMethod = "GET")
    @ApiResponses({
            @ApiResponse(code = 200,message = "删除成功"),
            @ApiResponse(code = 400,message = "参数接口问题"),
            @ApiResponse(code = 500,message = "后端错误"),
    })
    @ResponseBody
    public JsonResult queryDept1(){

        return  employeeService.queryDept1();
    }







       /*
        *  新增角色，新增权限
        */
    @RequestMapping(value = "/addRole",method = RequestMethod.POST)
    @ApiOperation(value = "新增角色",notes = "新增角色，创建权限",response = R.class,httpMethod = "post")
    @ApiResponses({
            @ApiResponse(code = 200,message = "删除成功"),
            @ApiResponse(code = 400,message = "参数接口问题"),
            @ApiResponse(code = 500,message = "后端错误"),
    })
    @ResponseBody
    public R addRole(@RequestBody @ApiParam(name ="Role_Anthority" ,value ="新增角色，创建权限") Role_Anthority role_anthority){


        return  employeeService.addRole_Anthority(role_anthority);
    }


       /*
        *  高级搜索
        */
       @RequestMapping(value = "/advancedSearch",method = RequestMethod.POST)
       @ApiOperation(value = "员工搜索",notes = "页面搜索",httpMethod = "POST", response = JsonResult.class)
       @ApiImplicitParams({
               @ApiImplicitParam(name = "page",value = "当前页码数,默认为1",paramType = "query",required = false,dataType ="String" ),
               @ApiImplicitParam(name = "pageSize",value = "每页显示条数,默认为10",paramType = "query",required = false,dataType ="String" ),
               @ApiImplicitParam(name = "advancedSearch",value = "搜索条件实体",paramType = "query",required = false,dataType ="AdvancedSearch" )
       })
       @ApiResponses({
               @ApiResponse(code=200,message = "success"),
               @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
               @ApiResponse(code=500,message = "后台错误"),
       })
       @ResponseBody
       public JsonResult queryEmployeeList(@RequestParam(defaultValue = "1")Integer page ,@RequestParam(defaultValue = "10")Integer pageSize ,AdvancedSearch advancedSearch){
           JsonResult jsonResult = employeeService.advancedSearch(page,pageSize,advancedSearch);


           return jsonResult;
       }




       /*
        *  删除部门
        */
@RequestMapping(value = "/delDept",method = RequestMethod.POST)
@ApiOperation(value = "删除部门",notes = "删除部门",response = R.class,httpMethod = "post")
@ApiResponses({
        @ApiResponse(code = 200,message = "查询成功"),
        @ApiResponse(code = 400,message = "参数接口问题"),
        @ApiResponse(code = 500,message = "后端问题"),
})
@ResponseBody
public JsonResult delDept(@RequestBody @ApiParam(name = "dept",value = "删除部门") Dept dept){
    JsonResult r= employeeService.delDept(dept);

    return r;
}




    /*
     *  删除员工
     */
    @RequestMapping(value = "/delEmployee",method = RequestMethod.POST)
    @ApiOperation(value = "删除员工",notes = "删除员工",response = R.class,httpMethod = "post")
    @ApiResponses({
            @ApiResponse(code = 200,message = "查询成功"),
            @ApiResponse(code = 400,message = "参数接口问题"),
            @ApiResponse(code = 500,message = "后端问题"),
    })
    @ResponseBody
    public JsonResult delEmployee(@RequestBody @ApiParam(name = "dept",value = "删除部门") Employee employee){
        JsonResult r= employeeService.delEmployee(employee);

        return r;
    }




    /*
     *  删除角色
     */
    @RequestMapping(value = "/delRole",method = RequestMethod.POST)
    @ApiOperation(value = "删除角色",notes = "删除角色",response = R.class,httpMethod = "post")
    @ApiResponses({
            @ApiResponse(code = 200,message = "查询成功"),
            @ApiResponse(code = 400,message = "参数接口问题"),
            @ApiResponse(code = 500,message = "后端问题"),
    })
    @ResponseBody
    public JsonResult delRole(@RequestBody @ApiParam(name = "role",value = "删除角色") Role role){
        JsonResult r= employeeService.delRole(role);

        return r;
    }
}

